import java.nio.file.Path;
import java.nio.file.Paths;

public class PathsTest {

    public static void main(String[] args) {

        // 默认
        Path path = Paths.get("D:/test.txt");
        // 通过组合形式
        Path path2 = Paths.get("D:/test", "123.txt");
        // 相对路径
        Path path3 = Paths.get(".");

        System.out.println("path toAbsolutePath=" + path.toAbsolutePath());
        System.out.println("path2 toAbsolutePath=" + path2.toAbsolutePath());
        System.out.println("path3 toAbsolutePath=" + path3.toAbsolutePath());
        System.out.println("path3 isAbsolute=" + path3.isAbsolute());

        Path path4 = Paths.get("D:\\Program Files");
        Path path5 = Paths.get("D:\\Program Files\\Java\\jdk1.8.0_241");

        // 相对论
        System.out.println("path4 relative path5=" + path4.relativize(path5));
        System.out.println("path5 relative path4=" + path5.relativize(path4));
    }

}
